//
//  CLHTableViewViewModel.m
//  ListViewModel_Example
//
//  Created by 曹连华 on 2019/7/30.
//  Copyright © 2019 clh2046@163.com. All rights reserved.
//

#import "CLHTableViewViewModel.h"
#import "CLHTableViewTVCellStyle0RowModel.h"
#import "CLHTableViewTVCellStyle1RowModel.h"
#import "CLHTableViewCollectionViewTVCellModel.h"

@implementation CLHTableViewViewModel

- (void)resetDataSource {
    [self.dataSource resetSectionList:[self sections]];
    self.dataSource.sectionIndexTitles = @[@"A",@"B",@"C",@"D",@"E"];
}

- (LVBaseCellRowModel *)didSelectedRowModelWithIndexPath:(NSIndexPath *)indexPath completionBlock:(LVCompletionBlock)completionBlock {
    LVBaseCellRowModel *rowModel = [self.dataSource rowModelAtIndex:indexPath];
    NSLog(@"点击了 section = %ld %@",(long)indexPath.section,rowModel.mainTitle);
    if (indexPath.row == 0) {
        [self showLoading];
    } else if (indexPath.row == 1) {
        [self showLoadingWithMessage:@"1111"];
    } else if (indexPath.row == 2) {
        [self hideLoading];
    }else if (indexPath.row == 3) {
        [self reloadTableView];
    }
    return rowModel;
}

- (NSArray <LVBaseCellSectionModel *> *)sections {
    
    NSMutableArray *arr = [NSMutableArray array];
    
    for (int i = 0 ; i < 5; i ++) {
        int arc = i%2;
        
        if (arc == 0) {
            LVBaseCellSectionModel *sectionModel = [[LVBaseCellSectionModel alloc]initWithRowList:[self row0s]];
           
            sectionModel.sectionHeader = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionHeader" size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 50) ];
            sectionModel.sectionHeader.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionHeaderView",i];

            sectionModel.sectionFooter = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionFooter"  size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 30) ];
            sectionModel.sectionFooter.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionFooterView",i];
            
            [arr addObject:sectionModel];
        } else {
            LVBaseCellSectionModel *sectionModel = [[LVBaseCellSectionModel alloc]initWithRowList:[self row1s]];
           
            sectionModel.sectionHeader = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionHeader" size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 50)];
            sectionModel.sectionHeader.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionHeaderView",i];
            
            sectionModel.sectionFooter = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionFooter" size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 30)];
            sectionModel.sectionFooter.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionFooterView",i];
            
            [arr addObject:sectionModel];
        }
        
    }
    
    
    return arr;
}


- (NSArray <CLHTableViewTVCellStyle0RowModel *> *)row0s {
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < 5; i++) {
        CLHTableViewTVCellStyle0RowModel *row = [[CLHTableViewTVCellStyle0RowModel alloc]initWithCellClass:@"CLHTableViewTVCellStyle0"];
        row.mainTitle = [NSString stringWithFormat:@"row = %d",i];
        row.rowHeight = 80;
        row.editingStyle = UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
        row.canEdit = YES;
        row.canMove = YES;
        row.titleForEdit = @"删除";
        [arr addObject:row];
    }
    CLHTableViewCollectionViewTVCellModel *rowModel = [[CLHTableViewCollectionViewTVCellModel alloc]initWithCellClass:@"CLHTableViewCollectionViewTVCell"];
    rowModel.rowHeight = 200;
    [arr addObject:rowModel];
    return arr;
}

- (NSArray <CLHTableViewTVCellStyle1RowModel *> *)row1s {
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < 5; i++) {
        CLHTableViewTVCellStyle1RowModel *row = [[CLHTableViewTVCellStyle1RowModel alloc]initWithCellClass:@"CLHTableViewTVCellStyle1"];
        row.mainTitle = [NSString stringWithFormat:@"row = %d",i];
        row.rowHeight = 80;
        row.editingStyle = UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
        row.canEdit = YES;
        row.canMove = YES;
        row.titleForEdit = @"删除";
        [arr addObject:row];
    }
    
    CLHTableViewCollectionViewTVCellModel *rowModel = [[CLHTableViewCollectionViewTVCellModel alloc]initWithCellClass:@"CLHTableViewCollectionViewTVCell"];
    rowModel.rowHeight = 200;
    [arr addObject:rowModel];
    return arr;
}

@end
